<template>
  <div class="page-container">
    <!-- 卡片 -->
    <el-card class="card-container">
      <el-form ref="form" :model="form" label-width="80px">
        <!-- 标题 -->
        <el-form-item label="学院名称">
          <el-input
              v-model="TipTitel"
              placeholder="请输入学院名称"
              maxlength="8"
              show-word-limit
              style="width: 30%;"></el-input>
        </el-form-item>

        <!-- 部门 -->
        <el-form-item label="所属学院">
          <el-select v-model="TipTypeId" placeholder="请选择" style="width: 30%;margin-right: 10px">
            <el-option
                v-for="(dept, index) in deptlist"
                :key="index"
                :label="dept.dept_name"
                :value="dept.dept_id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <!-- 仅保留发布公告按钮 -->
          <button class="pushable" @click.prevent="publish">
            <span class="shadow"></span>
            <span class="edge"></span>
            <span class="front"> 创建学院 </span>
          </button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 遮罩层 -->
    <div v-if="loading" class="loading-overlay">
      <loading/>
    </div>
  </div>
</template>

<script>
import {addtip} from "@/api/api";
import Loading from "@/components/Loading.vue";

export default {
  name: 'TopicForm',
  components: {Loading},
  data() {
    return {
      loading:false,
      TipTitel: '',
      deptlist:[],
      TipTypeId: 0,
      TipText:'',
      form: {}
    };
  },
  created() {
    this.initdept();
  },
  methods: {
    async initdept() {
      this.deptlist = this.$store.state.deptList;
    },
    async publish() {
      this.loading = true;
      try {
        const response = await addtip({
          TipTitel: this.TipTitel,
          TipText: this.TipText,
          TipTypeId: this.TipTypeId,
        });

        if (response.data.message === "成功") {
          this.$confirm('创建成功', '提示', {
            confirmButtonText: '确定',
            showCancelButton: false,
            type: 'success'
          }).then(() => {
            this.$router.go(-1); // 返回上一页
          });
        } else {
          this.$message.error("创建失败");
        }
      } catch (error) {
        this.$message.error("创建失败");
      } finally {
        this.loading = false;
      }
    }
  },
};
</script>

<style scoped>
.page-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.card-container {
  width: 90%;
  max-width: 800px;
  padding: 20px;
}

.custom-textarea {
  width: 100%;
  max-width: 800px;
}

.pushable {
  position: relative;
  background: transparent;
  padding: 0px;
  border: none;
  cursor: pointer;
  outline-offset: 4px;
  outline-color: deeppink;
  transition: filter 250ms;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.shadow {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: hsl(226, 25%, 69%);
  border-radius: 8px;
  filter: blur(2px);
  will-change: transform;
  transform: translateY(2px);
  transition: transform 600ms cubic-bezier(0.3, 0.7, 0.4, 1);
}

.edge {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  border-radius: 8px;
  background: linear-gradient(
      to right,
      hsl(248, 39%, 39%) 0%,
      hsl(248, 39%, 49%) 8%,
      hsl(248, 39%, 39%) 92%,
      hsl(248, 39%, 29%) 100%
  );
}

.front {
  display: block;
  position: relative;
  border-radius: 8px;
  background: hsl(248, 53%, 58%);
  padding: 16px 32px;
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 1rem;
  transform: translateY(-4px);
  transition: transform 600ms cubic-bezier(0.3, 0.7, 0.4, 1);
}

.pushable:hover {
  filter: brightness(110%);
}

.pushable:hover .front {
  transform: translateY(-6px);
  transition: transform 250ms cubic-bezier(0.3, 0.7, 0.4, 1.5);
}

.pushable:active .front {
  transform: translateY(-2px);
  transition: transform 34ms;
}

.pushable:hover .shadow {
  transform: translateY(4px);
  transition: transform 250ms cubic-bezier(0.3, 0.7, 0.4, 1.5);
}

.pushable:active .shadow {
  transform: translateY(1px);
  transition: transform 34ms;
}

.pushable:focus:not(:focus-visible) {
  outline: none;
}
</style>